package 优先级队列_堆;

/**
 * https://leetcode-cn.com/problems/compare-version-numbers/
 * 1、把两个字符串分别转换为数组；2、parseInt可以去零，将转换后的数字进行比较
 */
public class 比较版本号 {
    public int compareVersion(String version1, String version2) {
        String[] ver1 = version1.split("\\.");
        String[] ver2 = version2.split("\\.");
        int ver1Cur = 0 ; int ver2Cur = 0;
        int ver1Length = ver1.length ; int ver2Length = ver2.length;
        while (ver1Cur < ver1Length || ver2Cur < ver2Length){
            int i = 0 ; int j = 0;
            if (ver1Cur < ver1Length){
                i = Integer.parseInt(ver1[ver1Cur]);
            }
            if (ver2Cur < ver2Length){
                j = Integer.parseInt(ver2[ver2Cur]);
            }
            if (i != j){
                return i > j ? 1 : -1;
            }
            ver1Cur++ ; ver2Cur++;
        }
        return 0;
    }
}
